#!/bin/bash
#

##ssh免密配置

# 判断本机是否存在密钥，若有，公钥私钥都直接删除
if [ -e /root/.ssh/id_rsa ]; then
    rm -rf /root/.ssh/id_rsa*
fi

# 生成密钥对
ssh-keygen -t rsa -f ~/.ssh/id_rsa -P "" &> /dev/dull

# 判断known_hosts文件中是否包含对方主机的密钥信息。若有，直接用空白覆盖known_hosts文件
if [ -f /root/.ssh/known_hosts ]; then
    > /root/.ssh/known_hosts
fi

#向远端主机拷贝公钥
for i in 30 31; do
/usr/bin/expect << eof
set timeout 10
spawn ssh-copy-id root@192.168.110.$i
expect "(yes/no)?"
send "yes\n"
expect "password:"
send "123456\n"
expect eof
eof
echo "---------与192.168.110.${i}的ssh免密配置完毕---------"
done
